package com.wanxi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.ContactService;
import com.wanxi.vo.ContactVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
 * @author Chengbo Zhang
 */
@RestController
@RequestMapping("/admin/contact")
@CrossOrigin(origins = "http://localhost:8081")
public class ContactController {
    @Autowired
    ContactService contactService;

    @GetMapping("/findAll")
    public ResultDTO findAllContact(){
        return contactService.findAllContact();
    }

    @PutMapping("/add")
    public ResultDTO addContact(ContactVO contactVO){
        return contactService.addContact(contactVO);
    }

    @DeleteMapping("/delete")
    @PreAuthorize("hasAuthority('deleteContact')")
    public ResultDTO deleteContact(ContactVO contactVO){
        return contactService.deleteContact(contactVO);
    }

    @PostMapping("/findById")
    public ResultDTO findContactById(ContactVO contactVO){
        return contactService.findContactById(contactVO);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('updateContact')")
    public ResultDTO updateContact(ContactVO contactVO){
        return contactService.updateContact(contactVO);
    }

    @PostMapping("/updateEnable")
    @PreAuthorize("hasAuthority('updateContact')")
    public ResultDTO updateContactEnable(ContactVO contactVO){
        return contactService.updateEnable(contactVO);
    }
}
